#include<bits/stdc++.h>
using namespace std;
int n , k;
struct node{
	int x;
	int step;
}q[100001];
int vis[100001];
void bfs(int sx , int ex){
	int head = 1 , tail = 1;
	q[tail].x = sx;
	q[tail].step = 0;
	tail++;
	vis[sx] = 1;
	while(head < tail){
		int x0 = q[head].x;
		int step = q[head].step;
		if(x0 == ex){
			cout << step << endl;
		}
		for(int i = 1 ; i <= 3 ; i++){
			int nx;
			if(i == 1){
				nx = x0 + 1;
			} 
			else if(i == 2){
				nx = x0 - 1;
			} 
			else if(i == 3){
				nx = x0 * 2;
			}
			if(nx >= 0 && nx <= 100000 && !vis[nx]){
				q[tail].x = nx;
				q[tail].step = step + 1;
				tail++;
				vis[nx] = 1;
			}
		}
		head++;
	}
}
int main(){
	int m;
	cin >> m;
	for(int i = 1 ; i <= m ; i++){
		cin >> n >> k;
		memset(vis , 0 , sizeof(vis));
		bfs(n , k);
		return 0;
	}
} 
